package lhc.alg.top100;

/**
 * description: https://leetcode.cn/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/
 *  首尾指针得劲 快慢指针也能行但是交换次数相比较多
 * author: hongchen.liao
 * date:  2022/7/24
 */
public class _Offer_21 {

    class Solution {
        public int[] exchange(int[] nums) {
            int i = 0, j = nums.length - 1, tmp;
            while(i < j){
                while(i < j && (nums[i] & 1) == 1) i++;
                while(i < j && (nums[j] & 1) == 0) j--;
                tmp = nums[i];
                nums[i] = nums[j];
                nums[j] = tmp;
            }
            return nums;
        }
    }

}
